﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace JzSport.Api
{
    /// <summary>
    /// 编辑个人资料
    /// </summary>
    class EditProfileAction : AuthPostAction<Params.EditProfileParams,
        Results.EditProfileResult>
    {
        private static object s_lockDirObj = new object();

        protected override ActionResult<Results.EditProfileResult> OnExecute(ActionContext context, SysParameters sysParameters,
            Params.EditProfileParams opParams)
        {
            if (string.IsNullOrEmpty(opParams.NickName))
            {
                return new ActionResult<Results.EditProfileResult>(false, ErrorCode.Common_InvalidParameter,
                        ErrorCode.ToString(ErrorCode.Common_InvalidParameter), new Results.EditProfileResult());
            }

            ServiceResult<string> serviceResult = new AccountService().EditProfile(context.AccountId, opParams.NickName, opParams.Sex, opParams.City);

            Results.EditProfileResult actionResult = new Results.EditProfileResult();

            if (serviceResult.ErrorCode == ErrorCode.NoError)
            {
                return new ActionResult<Results.EditProfileResult>(true, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
            }
            return new ActionResult<Results.EditProfileResult>(false, serviceResult.ErrorCode,
                    ErrorCode.ToString(serviceResult.ErrorCode), actionResult);
        }
    }
}
